package com.lwm.controller;

import com.github.pagehelper.PageInfo;
import com.lwm.domain.MaterialRecord;
import com.lwm.domain.ResponseResult;
import com.lwm.service.MaterialRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物料档案控制层
 */
@RestController
@RequestMapping("/materialRecord")
public class MaterialRecordController {
    @Resource
    private MaterialRecordService materialRecordService;

    /**
     * 保存
     *
     * @param materialRecord 物料档案
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping
    public ResponseResult<Object> save(@RequestBody MaterialRecord materialRecord) {
        return materialRecordService.save(materialRecord);
    }

    /**
     * 删除
     *
     * @param ids 物料档案id
     * @return {@link ResponseResult}<{@link Object}>
     */
    @DeleteMapping
    public ResponseResult<Object> remove(@RequestBody List<Long> ids) {
        return materialRecordService.remove(ids);
    }

    /**
     * 编辑
     *
     * @param materialRecord 物料档案
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PutMapping
    public ResponseResult<Object> edit(@RequestBody MaterialRecord materialRecord) {
        return materialRecordService.edit(materialRecord);
    }

    /**
     * 分页
     *
     * @param page           页码
     * @param size           数量
     * @param materialRecord 物料档案
     * @return {@link ResponseResult}<{@link PageInfo}<{@link MaterialRecord}>>
     */
    @GetMapping("/page")
    public ResponseResult<PageInfo<MaterialRecord>> page(Integer page, Integer size, MaterialRecord materialRecord) {
        return materialRecordService.page(page, size, materialRecord);
    }

    /**
     * 根据id获取数据
     *
     * @param id 物料档案id
     * @return {@link ResponseResult}<{@link MaterialRecord}>
     */
    @GetMapping("/{id}")
    public ResponseResult<MaterialRecord> getById(@PathVariable Long id) {
        return materialRecordService.getById(id);
    }
}
